package com.xbongbong.paas.script.distributor.controller;


import com.xbongbong.paas.script.distributor.DistributorFee;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.pro.config.ProBaseConfig;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.script.pojo.dto.ProductDTO;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Locale;

/**
 * @author lee
 * @version v1.0
 * @date 2020/12/21 08:55
 * @since v1.0
 */
@RestController
@RequestMapping(XbbProConstant.API_ROOT_PREFIX + "/script/timed")
public class DistributorTimedScriptController {

    @Resource
    private ProBaseConfig proBaseConfig;
    @Resource
    private DistributorFee distributorFee;

    @RequestMapping(value = "/distributor", method = RequestMethod.POST)
    public void distributor(@RequestBody @Valid ProductDTO productDTO, BindingResult br) throws Exception {
        if (!proBaseConfig.getXbbCode().equals(productDTO.getXbbCode())) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100006);
        }
        LocaleContextHolder.setLocale(Locale.CHINA);
        long start = DateTimeUtil.getInt();
        Long now = DateTimeUtil.getTodayInt();
        distributorFee.distributorFeeClose(start, now);
        distributorFee.distributorCompanyConfigClose(start, now);
    }

}
